package com.ithemai.work;


import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;

/**
 * @auther Macrydy
 * @date 2020/7/4 19:42
 * 5.3 题目三: 软件配置信息(配置文件properties)
 * 1.把一下信息写到config.properties文件上.
 * username=zs
 * password=123
 * color=red
 * 2.键盘录入要登陆的用户名和密码.判断是否正确打印登陆成功和登陆失败.
 *
 * 3.如果登陆成功要读取该用户的color属性的值.
 * 如果color=red  打印红色日志到控制台.   // System.err.println(prop);
 * 如果color=black 打印黑色日志到控制台.
 */
public class Test10 {
    public static void main(String[] args) throws IOException {

        BufferedWriter bw = new BufferedWriter(new FileWriter("config.properties"));
        bw.write("username=zs");
        bw.newLine();
        bw.write("password=123");
        bw.newLine();
        bw.write("color=red");
        bw.flush();
        bw.close();

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = sc.nextLine();
        System.out.println("请输入密码：");
        String password = sc.nextLine();

        Properties properties = new Properties();
        properties.load(new FileReader("config.properties"));
        if (properties.getProperty("username").equals(username)&&properties.getProperty("password").equals(password)){
            System.out.println("登陆成功");
        }else {
            System.err.println("登录失败");
        }
    }
}
